<?php

/**
* wechatController.php
*
* 微信控制器
*
* @author witiq <微信号：937731903>
* @version 1.0
* @package controller
*/
require_once('adminController.php');
class menuController extends adminController {

	/**
	 * 
	 *@var initphp_list 
	 */
	public $initphp_list = array('manage','add|get','addPost|post','edit|get','editPost|post','delete|ajax-post','order|post'); 

	/**
	 *@var 定义menu按钮
	 */
	protected $menu_buttons = array('add','order');

	/**
	 *@var 需要渲染的字段列表键值对  array('fieldname'=>'viewname')
	 */
	protected $view_fields  = array(
							 'id'   =>array('name'=>'ID','type'=>'key','note'=>''),
							 'men_parentId'=>array('name'=>'父菜单','type'=>'treelist','note'=>''),							
							 'men_name' =>array('name'=>'菜单名称','type'=>'text','note'=>''),
							 'men_m' =>array('name'=>'模块','type'=>'text','note'=>'','notinlist'=>0,'width'=>'100'),
							 'men_c' =>array('name'=>'控制器','type'=>'text','note'=>'','notinlist'=>0,'width'=>'150'),
							 'men_a' =>array('name'=>'方法','type'=>'text','note'=>'','notinlist'=>0,'width'=>'150'),
							 'men_extend' =>array('name'=>'扩展','type'=>'text','note'=>''),
							 'men_desc' =>array('name'=>'描述','type'=>'text','note'=>'','notinlist'=>0,'width'=>'100'),
							);

	protected $service_name = 'menu';

	/**
	 * [configFields description]
	 * @return [type] [description]
	 */
	protected function config(){
		$this->function_fields['search'] = 'men_name';
		$this->function_fields['tree_name_field'] = 'men_name';
		$this->function_fields['order_field'] = 'men_order';
		$this->treelist_fields['men_parentId'] = array();
	}


	/**
	 * 添加分类页面
	 * @param   $_POST['user']
	 * @type  page
	 */
	public function add(){
		$this->doAdminAuth();
		$this->treelist_fields['men_parentId'] = $this->ownService->getTree();
		$this->setViewFields();
		$this->view->set_tpl('admin/'.$this->service_name .'_add');
		$this->view->display();
	}

	public function edit(){
		$this->doAdminAuth();
	    $id = isset($_GET[$this->table_key]) ? intval($this->controller->get_gp($this->table_key)) : exit('');
		$model  = $this->ownService->getModel($id);
		$this->treelist_fields['men_parentId'] = $this->ownService->getTree(0,$model['men_parentId']);
		$this->setViewFields();
		$this->view->assign('model',$model);
		$this->view->set_tpl('admin/'.$this->service_name .'_edit');
		$this->view->display();

	} 

	public function manage(){
   		$this->doAdminAuth();  
	    $fields = $this->getSearchFields();
	    $page_data = $this->ownService->getTreeArray();
		$this->setViewFields();
	    $this->view->assign('tree_list',$page_data);  
	    $this->view->assign('menu_buttons',$this->menu_buttons);
		$this->view->set_tpl('admin/'.$this->service_name .'_list');
		$this->view->display();
	}


}